# -*- coding: utf-8 -*-
from jms.aigroup.ai_group.train_sample_new import jms_ai_group__train_sample_new
from jms.aigroup.ai_dwd.yl_threesegcode_pdd_waybill import jms_ai_dwd__yl_threesegcode_pdd_waybill
from jms.dwd.oms.dwd_yl_oms_oms_order_incre_dt import jms_dwd__dwd_yl_oms_oms_order_incre_dt
from jms.dwd.oms.dwd_yl_oms_oms_waybill_incre_dt import jms_dwd__dwd_yl_oms_oms_waybill_incre_dt
from jms.dim.dim_mysql_lmdm_sys_first_code import jms_dim__dim_mysql_lmdm_sys_first_code
from jms.dim.dim_mysql_lmdm_sys_second_code import jms_dim__dim_mysql_lmdm_sys_second_code
from jms.dim.dim_mysql_lmdm_sys_tail_dispatch_area import jms_dim__dim_mysql_lmdm_sys_tail_dispatch_area
from jms.dim.dim_mysql_lmdm_sys_tail_dispatch_area_staff import jms_dim__dim_mysql_lmdm_sys_tail_dispatch_area_staff
from jms.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms.dim.lmdm.dim_yl_sys_package_different_base import jms_dim__dim_yl_sys_package_different_base
from jms.dwd.oms.dwd_yl_oms_interceptorpiece_base_dt import jms_dwd__dwd_yl_oms_interceptorpiece_base_dt
from jms.dwd.tab.dwd_tab_end_piece_base_dt import jms_dwd__dwd_tab_end_piece_base_dt

from utils.operators.latest_only_spark_submit_operator import LatestOnlySparkSubmitOperator
from utils.alerts.yl_threeSegCodeOnFailue import yl_threeSegCodeOnFailure
from utils.alerts.yl_threeSegCodeOnSuccess import yl_threeSegCodeOnSuccess

def kwargs():
    kwargs = {
        "db": "ai_group",
        "table": "yl_threesegcode_sign",
        "desc": "PDD流量运单签收三段码数据",
        "taskid": "10110",
        "ifprivacy": 1,
        "warnignore": 0,
    }
    return kwargs

jms_ai_dwd__yl_threesegcode_sign = LatestOnlySparkSubmitOperator(
    task_id='jms_ai_dwd__yl_threesegcode_sign',
    conn_id='spark_default',
    email=['jarl.huang@jtexpress.com','yl_bigdata@yl-scm.com'],
    pool_slots=6,
    task_concurrency=1,  # 如果任务不支持并发，则将 task_concurrency 设为 1
    name='jms_ai_dwd__yl_threesegcode_sign_{{ execution_date | date_add(1) | cst_ds }}',  # yarn 任务名称
    yarn_queue='pyspark',
    driver_memory='8G',
    executor_memory='10G',
    executor_cores=4,
    num_executors=70,
    depends_on_past=True,
    priority_weight=10, ##优先级，权重，默认下游任务多优先级就高
    conf={'spark.executor.memoryOverhead': 2048,
          'spark.core.connection.ack.wait.timeout': 300,
          'spark.dynamicAllocation.maxExecutors': 90,
          'spark.default.parallelism': 1000,
          'spark.locality.wait': 60,
          'spark.default.paralleism': '600',  # spark.default.parallelism只有在处理RDD时有效.
          'spark.sql.shuffle.partitions': 1000,  # spark.sql.shuffle.partitions则是只对SparkSQL有效
          'spark.shuffle.memoryFraction': '0.8',
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=4'
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 100000,
              'hive.exec.max.dynamic.partitions.pernode': 100000,
              },
    java_class='com.yunlu.bigdata.jobs.ml.ThreesegcodeSignWaybill',  # spark 主类
    # application='hdfs:///user/spark/work/aigroup/yl_threesegcode_sign/jobs-1.0-SNAPSHOT-jar-with-dependencies.jar',
    application='hdfs:///scheduler/jms/spark/sj/yl_threesegcode_sign/jobs-1.0-SNAPSHOT-jar-with-dependencies.jar',
    # spark jar 包
    application_args=['{{ execution_date | date_add(-1) | cst_ds_nodash }}', '{{ execution_date | cst_ds_nodash }}'],
    # 参数dt 20201026
    on_success_callback=yl_threeSegCodeOnSuccess(kwargs(), dingding_conn_id="dingding_ThreeSeg_etl_info"),
    on_failure_callback=yl_threeSegCodeOnFailure(kwargs(), dingding_conn_id="dingding_ThreeSeg_etl_alert")
)


# 设置依赖
jms_ai_dwd__yl_threesegcode_sign << [
    jms_dwd__dwd_yl_oms_oms_order_incre_dt,
    jms_ai_dwd__yl_threesegcode_pdd_waybill,
    jms_dwd__dwd_yl_oms_oms_waybill_incre_dt,
    jms_dim__dim_mysql_lmdm_sys_first_code,
    jms_dim__dim_mysql_lmdm_sys_second_code,
    jms_dim__dim_mysql_lmdm_sys_tail_dispatch_area,
    jms_dim__dim_mysql_lmdm_sys_tail_dispatch_area_staff,
    jms_dim__dim_network_whole_massage,
    jms_dim__dim_yl_sys_package_different_base,
    jms_dwd__dwd_yl_oms_interceptorpiece_base_dt,
    jms_dwd__dwd_tab_end_piece_base_dt,
    jms_ai_group__train_sample_new
]
